package autolayoutlib.config;

import android.content.Context;

import autolayoutlib.utils.AutoUtils;

public class AutoLayoutConifg
{

    private static AutoLayoutConifg sIntance = new AutoLayoutConifg();


    private static final String KEY_DESIGN_WIDTH = "design_width";
    private static final String KEY_DESIGN_HEIGHT = "design_height";

    private int mScreenWidth;
    private int mScreenHeight;

    // 产品UI设计图尺寸:
    public static int mDesignWidth = 1080;
    public static int mDesignHeight = 1920;

    private boolean useDeviceSize;


    private AutoLayoutConifg()
    {
    }

    public void checkParams()
    {
        if (mDesignHeight <= 0 || mDesignWidth <= 0)
        {
            throw new RuntimeException(
                    "you must set " + KEY_DESIGN_WIDTH + " and " + KEY_DESIGN_HEIGHT + "  in your manifest file.");
        }
    }

    public AutoLayoutConifg useDeviceSize()
    {
        useDeviceSize = true;
        return this;
    }


    public static AutoLayoutConifg getInstance()
    {
        return sIntance;
    }


    public int getScreenWidth()
    {
        return mScreenWidth;
    }

    public int getScreenHeight()
    {
        return mScreenHeight;
    }

    public int getDesignWidth()
    {
        return mDesignWidth;
    }

    public int getDesignHeight()
    {
        return mDesignHeight;
    }


    public void init(Context context, int designWidth, int designHeight)
    {
        int[] screenSize = AutoUtils.getAutoScreenSize(context);
        mScreenWidth = screenSize[0];
        mScreenHeight = screenSize[1];
        mDesignWidth = designWidth;
        mDesignHeight = designHeight;
    }

//    private void getMetaData(Context context)
//    {
//        PackageManager packageManager = context.getPackageManager();
//        ApplicationInfo applicationInfo;
//        try
//        {
//            applicationInfo = packageManager.getApplicationInfo(context
//                    .getPackageName(), PackageManager.GET_META_DATA);
//            if (applicationInfo != null && applicationInfo.metaData != null)
//            {
//                mDesignWidth = (int) applicationInfo.metaData.get(KEY_DESIGN_WIDTH);
//                mDesignHeight = (int) applicationInfo.metaData.get(KEY_DESIGN_HEIGHT);
//            }
//        } catch (PackageManager.NameNotFoundException e)
//        {
//            throw new RuntimeException(
//                    "you must set " + KEY_DESIGN_WIDTH + " and " + KEY_DESIGN_HEIGHT + "  in your manifest file.", e);
//        }
//
//        L.e(" designWidth =" + mDesignWidth + " , designHeight = " + mDesignHeight);
//    }
}
